package model.impl;

import java.util.List;

import model.bo.Articletype;
import model.dao.IArticletypeDAO;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

/**
 * Data access object (DAO) for domain model class Articletype.
 * 
 * @see model.bo.Articletype
 * @author MyEclipse Persistence Tools
 */

public class ArticletypeDAO extends HibernateDaoSupport implements IArticletypeDAO {
	private static final Log log = LogFactory.getLog(ArticletypeDAO.class);

	protected void initDao() {
		// do nothing
	}

	/* (non-Javadoc)
	 * @see model.impl.IArticletypeDAO#save(model.bo.Articletype)
	 */
	public void save(Articletype transientInstance) {
		log.debug("saving Articletype instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see model.impl.IArticletypeDAO#delete(model.bo.Articletype)
	 */
	public void delete(Articletype persistentInstance) {
		log.debug("deleting Articletype instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see model.impl.IArticletypeDAO#findById(java.lang.Integer)
	 */
	public Articletype findById(java.lang.Integer id) {
		log.debug("getting Articletype instance with id: " + id);
		try {
			Articletype instance = (Articletype) getHibernateTemplate().get(
					"model.bo.Articletype", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see model.impl.IArticletypeDAO#findByExample(model.bo.Articletype)
	 */
	public List findByExample(Articletype instance) {
		log.debug("finding Articletype instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see model.impl.IArticletypeDAO#findByProperty(java.lang.String, java.lang.Object)
	 */
	public List findByProperty(String propertyName, Object value) {
		log.debug("finding Articletype instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from Articletype as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see model.impl.IArticletypeDAO#findByTypename(java.lang.Object)
	 */
	public List findByTypename(Object typename) {
		return findByProperty(TYPENAME, typename);
	}

	/* (non-Javadoc)
	 * @see model.impl.IArticletypeDAO#findByFatherid(java.lang.Object)
	 */
	public List findByFatherid(Object fatherid) {
		return findByProperty(FATHERID, fatherid);
	}

	/* (non-Javadoc)
	 * @see model.impl.IArticletypeDAO#findAll()
	 */
	public List findAll() {
		log.debug("finding all Articletype instances");
		try {
			String queryString = "from Articletype order by fatherid";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see model.impl.IArticletypeDAO#merge(model.bo.Articletype)
	 */
	public Articletype merge(Articletype detachedInstance) {
		log.debug("merging Articletype instance");
		try {
			Articletype result = (Articletype) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see model.impl.IArticletypeDAO#attachDirty(model.bo.Articletype)
	 */
	public void attachDirty(Articletype instance) {
		log.debug("attaching dirty Articletype instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see model.impl.IArticletypeDAO#attachClean(model.bo.Articletype)
	 */
	public void attachClean(Articletype instance) {
		log.debug("attaching clean Articletype instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static IArticletypeDAO getFromApplicationContext(
			ApplicationContext ctx) {
		return (IArticletypeDAO) ctx.getBean("ArticletypeDAO");
	}
}